<template>
	<view class="form-container">
		<!-- form演示 -->
		<view class="form-group">
			<form class="form-main">
				<view class="form-group">
					<h3>托盘码</h3>
					<view>
						<input id="user-insert-line" :focus="focus1" type="number" name="input" 
						@input="INPUT" v-model="model.traycode"
							placeholder="托盘码" />
					</view>
				</view>
				<view class="form-group"><button @click="postMES" form-type="submit">上报MES</button>
				</view>
				<view class="form-group"><button type="default" @click="clear" form-type="reset">重置</button></view>
			</form>
		</view>
	</view>
</template>

<script>
	import comboxSearch from "@/components/cuihai-combox/cuihai-combox.vue"
	import uniSection from "@/components/uni-section.vue"
	export default {
		components: {
			comboxSearch,
			uniSection
		},
		data() {
			return {
				candidates: null,
				productionInfo: null,
				model: {
					traycode: '',
				},
				focus1: true,
				focus2: false,
			}
		},
		onLoad() {
			this.screenHeight = uni.getSystemInfoSync().windowHeight;
		},
		methods: {
			postMES() {
				uni.request({
					/* 网页 调试接口 */
					//url: '/api/PDA/CallMaterial',
					url: that.$global.url2+':8090/apis/Acc/ProductProcess/DoSub',
					method: 'POST',
					sslVerify: false,
					data: {
						"MachineId": 129051,
						"MachineType": 501,
						"ActionTypeId": 2,
						"data": {
							"TrayCode": this.model.traycode,
							"Params":[
								{
									"ParamType":"TemperatureTop",
									"ParamValue":"42.6℃",
									"Position":"",
									"Result":1
								},
								{
									"ParamType": "TemperatureLowest",
									"ParamValue": "38.1℃",
									"Position": "",
									"Result": 1
								},
								{
									"ParamType": "HumidityTop",
									"ParamValue": "31.3%",
									"Position": "",
									"Result": 1
								},
								{
									"ParamType": "HumidityLowest",
									"ParamValue": "22.3%",
									"Position": "",
									"Result": 1
								}
							]
						}
					},
					header: {
						"Content-Type": "application/json; charset=UTF-8"
						//81037320063630027
					},
					success: (res) => {
						if (res.statusCode == 200 && res.data.ret == 1) {
							uni.showToast({
								icon: 'success',
								title: '出库上传MES成功!',
								mask: true,
							});
							console.log(res)
						} else {
							uni.showToast({
								icon: 'error',
								mask: true,
								title: res.data.data,
							})
						}
					},
					fail: (res) => {
						uni.showToast({
							icon: 'error',
							mask: true,
							title: "接口请求失败!",
						})
						console.log("error===" + res.errMsg)
					}
				})
			},
			clear() {
				this.productionInfo = null
			},
			INPUT(e) {
				// setInterval(()=>{
				// 	if (e.detail.value.length == 4) {
				// 		this.focus1 = false,
				// 		this.focus2 = true
				// 	}
				// 	console.log(111)
				// },200)
				console.log(e.detail.value)
				if (e.detail.value.length == 17) {
					this.focus1 = false,
						this.focus2 = true
				}
			},
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #EEF0F4;
		font-size: 18px;
	}

	u-button {
		float: left;
		display: inline;
	}

	.form {
		margin-top: 35rpx;
		width: 100%;
		padding: 0 20rpx;
	}

	.form-group {

		padding: 20rpx 30rpx 0rpx 30rpx;
	}

	.btnsubmit {
		margin-top: 50px;
	}

	#user-insert-line::before {
		position: absolute;
		right: 25px;
		bottom: 0;
		top: 5rem;
		left: 40px;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	#name::before {
		position: absolute;
		right: 25px;
		bottom: 0;
		top: 8.8rem;
		left: 40px;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}
</style>
